﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Aribaccio
{
    /// <summary>
    /// 定义扩展Ascii转换类
    /// </summary>
    public static class ExtendAscii
    {
        /// <summary>
        /// Ascii码字符的字符串 => Ascii码值的字节数组
        /// </summary>
        /// <param name="argAsciiString"></param>
        /// <returns></returns>
        public static byte[] ToAsciiBytes(this string argAsciiString)
        {
            if (argAsciiString == null) return new byte[0];
            return Encoding.ASCII.GetBytes(argAsciiString);
        }

        /// <summary>
        /// Ascii码值的字节数组 => Ascii码字符的字符串
        /// </summary>
        /// <param name="argAsciiBytes"></param>
        /// <returns></returns>
        public static string ToAsciiString(this byte[] argAsciiBytes)
        {
            if (argAsciiBytes == null || argAsciiBytes.Length <= 0) return string.Empty;
            return Encoding.ASCII.GetString(argAsciiBytes);
        }

        /// <summary>
        /// Ascii码值的字节 => Ascii码字符的字符串
        /// </summary>
        /// <param name="argAsciiByte"></param>
        /// <returns></returns>
        public static string ToAsciiString(this byte argAsciiByte)
        {
            return Encoding.ASCII.GetString(new byte[] { argAsciiByte });
        }
    }
}
